 ********************************************************************
 * Table 5: GENDER HETEROGENEITY IN PRICE EFFECT:
 * This do file estimates the Random Parameter Logit with price interacted with gender 
 ********************************************************************


 do "mixlogit.ado"
 do "mixlogit_d1.ado"
 do "mixlpred.ado"



 * load data to use
 use "data_acute_illness_patients_mixedlogit_vs4.dta", clear

 *Starting values
 
 * preliminary: gets the starting value and convergence
 
  set seed 545415
  mixlogit d_  dist_dw_hf_2 dist_22   nu_8g alt2-alt4  , group(choicesit) id(idid) rand( doctor_tot) 
  matrix b50 = e(b)
   
 
 tab female male
 
 * The coefficient of p_i1 gives the average price coefficient for male, the coefficient of p_i1*female gives the difference between male and female (the extra effect)
	gen p_i1_fem = p_i1*female
	gen p_i2_fem = p_i2*female
	gen p_i3_fem = p_i3*female
	gen p_i4_fem = p_i4*female

	gen p_i1_male = p_i1*male 
	gen p_i2_male = p_i2*male
	gen p_i3_male = p_i3*male 
	gen p_i4_male = p_i4*male 

* save the data for input into the elasticity bootstrapping routine
save "tempdata_mixedlogitboot_g.dta", replace

**********************************************************************************************************************************************
* Table 5: Health Provider Choice (RPM): Heterogeneity by gender (Model allowing price to differ by gender
**  Note that the interpretation of the interaction coefficients (p_i1_fem, p_i2_fem etc)  in this specification is the average impact for a group not the differential w.r.t males
***********************************************************************************************************************************************    
	set seed 201
     matrix b52g = b50[1,1..6], 0.0, 0.003, 0.26, 0.001, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  0.001, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
	 
	 * This converges at iteration 71.
	 mixlogit d_  dist_dw_hf_2 dist_22   nu_8d alt2-alt4 nu_8dsq , group(choicesit) id(idid) cluster(q01_10) rand(doctor_tot  generator2009 beds p_i1_male p_i2_male p_i3_male p_i4_male  p_i1_fem p_i2_fem p_i3_fem p_i4_fem  ) from(b52g, copy) tolerance(0.01)
	 
	mixlpred PR0GE, nrep(500)
	est store mixl52
	gen esample = (e(sample)==1)

